home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright Cornell University 1986. All rights are reserved.
-
- routines to save and retrieve configuration info, such as Control
- menu item state.
- */
-
- #include <em.h>
-
- #include <3270.h>
- #include <h19.h>
- #include <config.h>
- #include <macdefs.h>
- #include <resdefs.h>
- #include <util.h>
-
- #define CONFID 0
-
- #define VERS1 1
- #define VERS2 2
- #define VERS3 3
- #define VERS4 4
- #define VERS5 5
- #define VERS6 6
- #define VERS7 7
- #define VERS8 8
- #define VERS9 9
- #define VERS10 10
- #define VERS11 11
- #define VERS13 13
-
- #define CURVERSION VERS13 /* current config version number */
-
- #define GLOBVERSION 4
-
- #define VERS1KEYBOARD 11
- #define VERS1KEYPAD 14
-
- #define NEG (-1)
-
- SysEnvRec environs;
-
- short setresfid;
- short setresvref; /* volume ref num for Default file */
- short setresvol;
- long setresdir; /* "Comte Default" directory and volume */
-
- char * strsetcantopen = "Can't open 'Comet Default'";
- char * strbadvol = "Can't change directories";
-
- extern Handle modresource();
-
-
- /* get global configuration information */
-
- globalconfig()
- {
- Handle hsize;
-
- if ((hsize = GetResource('SIZE', (short) -1)) != NULL) {
- /* check to see if we are intended to run in background */
- if (**hsize & 0x04)
- /* "background only" has been set */
- mfbackonly = TRUE;
- ReleaseResource(hsize);
- }
-
- if (SysEnvirons(1, &environs)) {
- /* error("Your System is out of date!");
- too obtrusive! 512KE can't run the right system anyway... */
-
- keyboard = OLDKEYBOARD;
-
- }
- else {
- if (environs.keyBoardType == envUnknownKbd
- || environs.keyBoardType == envMacKbd
- || environs.keyBoardType == envMacAndPad)
- keyboard = OLDKEYBOARD;
- else
- keyboard = PLUSKEYBOARD;
- }
-
- }
-
- /* get the emulator configuration from the CONF resource */
-
- getconfig()
- {
- Handle hconfig;
- struct config * confp;
- Handle sizeh;
-
- sizeh = GetResource('Fsiz', (short) 0);
- if (sizeh != NULL) {
- emdp->fontsize = *((short *) *sizeh);
- ReleaseResource(sizeh);
- }
- else
- emdp->fontsize = 0; /* will use default font */
-
- /* get connect macro resource */
- emdp->connmacro = Get1Resource('CONN', 0);
- if (emdp->connmacro != NULL)
- DetachResource(emdp->connmacro);
-
- /* get close macro resource */
- emdp->closemacro = Get1Resource('CONN', 1);
- if (emdp->closemacro != NULL)
- DetachResource(emdp->closemacro);
-
- /* get double-click macro resource */
- emdp->clickmacro = GetResource('CLIK', 0);
- if (emdp->clickmacro != NULL)
- DetachResource(emdp->clickmacro);
-
- /* get TCP host address resource */
- emdp->hlasthost = Get1Resource('LHST', 0);
- if (emdp->hlasthost != NULL)
- DetachResource(emdp->hlasthost);
-
- defaultconf();
- if ((hconfig = GetResource('CONF', (short) CONFID)) == NULL) {
- /* default configuration */
- return(-1);
- }
-
- HLock(hconfig);
- confp = (struct config *) *hconfig;
-
- if (confp->version_number < VERS1) {
- /* do default configuration */
- error("Your document is damaged, using default");
- HUnlock(hconfig);
- ReleaseResource(hconfig);
- return(-1);
- }
- if (confp->version_number > CURVERSION) {
- error("Application predates the configuration version");
- }
- if (confp->version_number >= VERS1) {
- emdp->keypad = confp->keypad;
- if (confp->version_number == VERS1) {
- /* translate old keyboard values */
- emdp->keypad -= VERS1KEYPAD;
- }
- #ifndef ENVIRONS
- keyboard = confp->keyboard;
- if (confp->version_number == VERS1) {
- /* translate old keyboard values */
- keyboard -= VERS1KEYBOARD;
- }
- #endif
- emdp->dokeymacros = confp->dokeymacros;
- emdp->ibm_keymode = confp->ibm_mode;
- emdp->changecurs = confp->changecurs;
- emdp->blockcurs = confp->blockcurs;
- emdp->escmap = confp->escmap;
- emdp->ba_bs = confp->ba_bs;
- emdp->crtonl = confp->crtonl;
- emdp->typeahead = confp->typeahead;
- }
- if (confp->version_number >= VERS2) {
- emdp->nullsareblanks = confp->ibmnulls;
- emdp->squeezeblanks = confp->ibmsqueeze;
- emdp->curseekmode = confp->curseekmode;
-
- wrap_around = emdp->wrap_around = confp->termwrap;
-
- /*
- emdp->ucb.u_tftp = confp->tftpserve;
- emdp->ucb.u_ask = confp->tftpask;
- TODO global mess tftpserve, tftpask */
- }
- if (confp->version_number >= VERS3) {
- emdp->autoshrink = confp->autoshrink;
- }
- if (confp->version_number >= VERS4) {
- emdp->shiftfield = confp->shiftfield;
- }
- if (confp->version_number >= VERS5) {
- int index;
-
- /* make sure at least one terminal is enabled */
- for (index = 0; confp->disableterm[index] && index < TERMTYPECOUNT; index++)
- ;
- if (index >= TERMTYPECOUNT) {
- /* no terminals are enabled, surely a mistake of some sort! */
- error("Ignoring config error: all terminal types disabled");
- }
- else {
- int firstable;
-
- firstable = FALSE;
- for (index = 0; index < TERMTYPECOUNT; index++) {
- emdp->disableterm[index] = confp->disableterm[index];
-
- if (confp->disableterm[index] || firstable)
- continue;
-
- /* set the terminal by default to the first enabled one */
- emdp->termtype = index;
- firstable = TRUE;
- }
- }
- }
- if (confp->version_number >= VERS6) {
- if (environs.hasColorQD)
- /* only allow color to be set if Color QuickDraw is present! */
- emdp->color = confp->color;
- else
- emdp->color = FALSE;
- }
- if (confp->version_number >= VERS7) {
- emdp->ibmcolormap = confp->ibmcolormap;
- /* trydsdraw = confp->trydsdraw;
- riskydsdraw = confp->riskydsdraw;
- TODO should there be just one rather than per document? */
- }
- if (confp->version_number >= VERS8) {
- emdp->disposeonclose = confp->disposeonclose;
-
- emdp->normfont = confp->normfont;
- emdp->highfont = confp->highfont;
- emdp->vtfont = confp->vtfont;
- emdp->conntype = confp->conntype;
- }
- else {
- emdp->normfont = 201; /* normal font ID */
- emdp->highfont = 202; /* bold font ID */
- emdp->vtfont = 74; /* vt100 graphics font ID */
- }
- if (confp->version_number >= VERS9) {
- emdp->vtkeypad = confp->vtkeypad;
- }
- else {
- emdp->vtkeypad = FALSE;
- }
- if (confp->version_number >= VERS10) {
- emdp->logsession = confp->logsession;
- emdp->filesession = confp->filesession;
- emdp->editload = confp->editload;
- emdp->editdownwrap = confp->editwrap;
- }
- else {
- emdp->logsession = FALSE;
- emdp->filesession = FALSE;
- emdp->editload = TRUE;
- emdp->editdownwrap = FALSE;
- }
- if (confp->version_number >= VERS11) {
- emdp->autohangup = confp->autohangup;
- }
- else {
- emdp->autohangup = FALSE;
- }
- if (confp->version_number >= VERS13) {
- emdp->vtjumpscroll = confp->vtjumpscroll;
- emdp->keypadswitch = confp->keypadswitch;
- emdp->logerase = confp->logerase;
- emdp->editupwrap = confp->editupwrap;
-
- emdp->linecount = confp->linecount;
- emdp->linelength = confp->linelength;
- emdp->ibm_type = confp->ibm_type;
- }
- else {
- emdp->vtjumpscroll = FALSE;
- emdp->keypadswitch = FALSE;
- emdp->logerase = FALSE;
- emdp->editupwrap = FALSE;
-
- emdp->linecount = 24;
- emdp->linelength = 80;
- emdp->ibm_type = IBMMOD2;
- }
- setcontext(emdp); /* update globals */
-
- HUnlock(hconfig);
- ReleaseResource(hconfig);
- }
-
-
- /* release handles associated with window configuration */
-
- releaseconfig()
- {
- if (emdp->connmacro != NULL)
- DisposHandle(emdp->connmacro);
- emdp->connmacro = NULL;
-
- if (emdp->closemacro != NULL)
- DisposHandle(emdp->closemacro);
- emdp->closemacro = NULL;
-
- if (emdp->clickmacro != NULL)
- DisposHandle(emdp->clickmacro);
- emdp->clickmacro = NULL;
-
- if (emdp->hlasthost != NULL)
- DisposHandle(emdp->hlasthost);
- emdp->hlasthost = NULL;
-
- }
-
-
-
- /* set the CONF resource contents to current values of variables to be saved */
-
- setconfig(hconf)
- Handle hconf;
- {
- struct config * confp;
- int index;
-
- confp = (struct config *) *hconf;
-
- confp->version_number = CURVERSION;
- confp->keyboard = keyboard;
- confp->keypad = emdp->keypad;
- confp->dokeymacros = emdp->dokeymacros;
- confp->ibm_mode = emdp->ibm_keymode;
- confp->changecurs = emdp->changecurs;
- confp->blockcurs = emdp->blockcurs;
- confp->escmap = emdp->escmap;
- confp->ba_bs = emdp->ba_bs;
- confp->crtonl = emdp->crtonl;
- confp->typeahead = emdp->typeahead;
- confp->ibmnulls = emdp->nullsareblanks;
- confp->ibmsqueeze = emdp->squeezeblanks;
- confp->curseekmode = emdp->curseekmode;
-
- confp->termwrap = wrap_around;
- confp->tftpserve = emdp->ucb.u_tftp;
- confp->tftpask = emdp->ucb.u_ask;
- confp->autoshrink = emdp->autoshrink;
- confp->shiftfield = emdp->shiftfield;
-
- for (index = 0; index < TERMTYPEMAX; index++) {
- confp->disableterm[index] = emdp->disableterm[index];
- }
- confp->color = emdp->color;
- confp->ibmcolormap = emdp->ibmcolormap;
- confp->trydsdraw = trydsdraw;
- confp->disposeonclose = emdp->disposeonclose;
- confp->normfont = emdp->normfont;
- confp->highfont = emdp->highfont;
- confp->vtfont = emdp->vtfont;
- confp->conntype = emdp->conntype;
-
- confp->vtkeypad = emdp->vtkeypad;
-
- confp->logsession = emdp->logsession;
- confp->filesession = emdp->filesession;
- confp->editload = emdp->editload;
- confp->editwrap = emdp->editdownwrap;
-
- confp->autohangup = emdp->autohangup;
-
- confp->vtjumpscroll = emdp->vtjumpscroll;
- confp->keypadswitch = emdp->keypadswitch;
- confp->logerase = emdp->logerase;
- confp->editupwrap = emdp->editupwrap;
- confp->linecount = emdp->linecount;
- confp->linelength = emdp->linelength;
- confp->ibm_type = emdp->ibm_type;
-
- setlocalconfig();
- }
-
-
- /* open the resource files in the file selected by the user on launching */
-
- openlaunchres()
- {
- short mess;
- short count;
- short appcount;
- short refnum;
- short newresfid;
- WDPBRec WDPB;
- HPrmBlkRec HPB;
- Str255 bvname;
- char nosysconf = TRUE;
-
- /* we always expect a connection structure to exist */
- makeconn();
-
- WDPB.ioCompletion = NULL;
- WDPB.ioNamePtr = NULL;
- PBHGetVol(&WDPB, (Boolean) FALSE);
- appresfid = CurResFile();
- appvref = WDPB.ioVRefNum;
- appvol = WDPB.ioWDVRefNum; /* all vol settings from WDPBs used to use ioVRefNum */
- appdir = WDPB.ioWDDirID;
-
- /* try to open document in blessed folder, create it if necessary;
- this provides us with one file to store net configuration & host table,
- as well as providing user-configurable default configuration
- for new windows...
- */
- if (!environs.systemVersion) {
- /* pre IM-V ROM, we've gotta find the "Blessed Goddam Folder" ourselves... */
- bvname.length = 0;
- HPB.ioCompletion = NULL;
- HPB.ioNamePtr = &bvname;
- HPB.ioVRefNum = 0;
- HPB.u.hvp.ioVolIndex = 1; /* start w/ 1st vol */
-
- for (; ! PBHGetVInfo(&HPB, (Boolean) FALSE); HPB.u.hvp.ioVolIndex++) {
- /* there's another volume to check */
-
- if (HPB.u.hvp.ioVFndrInfo[0]) {
- /* We found a blessed folder, let's setvol to it */
- WDPB.ioCompletion = NULL;
- WDPB.ioNamePtr = NULL;
- WDPB.ioVRefNum = HPB.ioVRefNum;
- WDPB.ioWDDirID = HPB.u.hvp.ioVFndrInfo[0];
- PBHSetVol(&WDPB, (Boolean) FALSE);
-
- WDPB.ioNamePtr = NULL;
- PBHGetVol(&WDPB, (Boolean) FALSE);
-
- environs.sysVRefNum = WDPB.ioVRefNum;
- break;
- }
- }
- }
- if (SetVol((StringPtr) NULL, environs.sysVRefNum)) {
- error("Can't set volume to System Folder");
- }
- else {
- /* Get the vrefnum */
- WDPB.ioNamePtr = NULL;
- PBHGetVol(&WDPB, (Boolean) FALSE);
- setresvref = WDPB.ioVRefNum;
- setresvol = WDPB.ioWDVRefNum;
- setresdir = WDPB.ioWDDirID;
-
- if ((newresfid = myopenresfile(&setfile[0], setresvref, (Byte) fsRdWrPerm)) == -1) {
- /* no config, try make a config file in the system folder */
- if ((newresfid = makeconffile()) != -1) {
- /* we made the new file & set resfid, break */
- nosysconf = FALSE;
- }
- else {
- error("Can't create 'Comet Default' document in System Folder");
- }
-
- }
- else {
- /* get configuration from the existing default file */
- nosysconf = FALSE;
- }
- }
-
- if (nosysconf) {
- /* no blessed folder yet, make "Comet Default" conf in launch folder */
- if ((newresfid = myopenresfile(&setfile[0], appvref, (Byte) fsRdWrPerm)) == -1) {
- if ((newresfid = makeconffile()) == -1) {
- /* can't even make a conf file in the app folder */
- newresfid = appresfid;
- }
- else {
- error("Can't create 'Comet Default' document in application folder");
- }
- }
- else {
- /* we made the new file & set resfid, break */
- /* appresfid = newresfid; */
- nosysconf = FALSE;
- }
- setresvol = appvol;
- setresdir = appdir;
- setresvref = appvref;
- }
-
- getglobalconf();
- setresfid = newresfid;
-
- fillwindclose();
- /* close the copyright window if it's up */
-
- /* now check for document files */
- CountAppFiles(&mess, &appcount);
- if (appcount > 0 && mess == appOpen) {
- /* the Finder wants us to open some document files */
- /* open all document files, each representing one
- connection with configuration data */
-
- closesettings(); /* close the Settings file */
-
- for (count = 1; appcount--; ) {
- GetAppFiles(count++, &emdp->appfile);
- SetVol((StringPtr) NULL, emdp->appfile.vRefNum);
- if ( (newresfid = myopenresfile(&emdp->appfile.fName, emdp->appfile.vRefNum, (Byte) fsRdWrPerm) ) == -1) {
- error("Couldn't open document file");
- continue;
- /* TODO handle errors better; */
- }
- /* get the new vol/dir for SFPut */
- WDPB.ioNamePtr = NULL;
- PBHGetVol(&WDPB, (Boolean) FALSE);
- emdp->resfid = newresfid;
- emdp->resvref = WDPB.ioVRefNum;
- emdp->resvol = WDPB.ioWDVRefNum;
- emdp->resdir = WDPB.ioWDDirID;
-
- /* downloads default to document home */
- emdp->downvref = WDPB.ioVRefNum;
- emdp->downvol = WDPB.ioWDVRefNum;
- emdp->downdir = WDPB.ioWDDirID;
-
- getconfig();
-
- PtrToHand(&emdp->appfile.fName, &emdp->hhostname,
- (long) (emdp->appfile.fName.length + 1));
-
- /* check to see if TCP host name is OK before making window */
- if (emdp->conntype == CONN_MACTCP
- || emdp->conntype == CONN_CUTCP) {
- /* on startup, get the null-terminated c string from the resource file */
- if (emdp->hlasthost) {
- HLock(emdp->hlasthost);
- if (resolve_name(*emdp->hlasthost, &emdp->fhost)) {
- if (namewindow()) {
- /* no address, give the user a chance to fix things */
- HUnlock(emdp->hlasthost);
- continue;
- }
- }
- HUnlock(emdp->hlasthost);
- }
- else {
- if (namewindow()) {
- /* no address, give the user a chance to fix things */
- continue;
- }
- }
- }
- if (makewind()) {
- /* out of memory */
- error("Not enough memory to make a window!");
- killconn();
- break;
- }
- keyxinit();
-
- windowtitle(emdp, &emdp->appfile.fName);
- addwindmenu(emwindow);
-
- closeconfig(emdp); /* close after getting resources */
-
- openconn(emdp); /* open up the connection */
-
- if (appcount) {
- /* ready another connection */
- makeconn();
- }
- }
- }
- else {
- /* closesettings();
- TODO this would ensure Dick behavior: not getting saved
- window position etc. from settings file */
-
- emdp->resfid = setresfid;
- emdp->resvref = setresvref; /* settings directory--the system folder */
- emdp->resvol = setresvol;
- emdp->resdir = setresdir;
-
- emdp->downvref = appvref; /* download defaults into app directory */
- emdp->downvol = appvol;
- emdp->downdir = appdir;
-
- getconfig();
-
- /* set name to "Comet Default" */
- ptoc(&setfile[0]);
- strcpy(&emdp->appfile.fName, &setfile[0]);
- ctop(&emdp->appfile.fName);
- ctop(&setfile[0]);
-
- PtrToHand(&emdp->appfile.fName, &emdp->hhostname,
- (long) (emdp->appfile.fName.length + 1));
-
- if (mfbackonly) {
- releaseconn(emdp);
- }
- else {
- /* do namewindow() with "Comet Default" */
-
- if (namewindow()) {
- /* cancelled */
- int tquit = quitonclose;
- /* don't quit if user cancels this dialog on startup! */
-
- quitonclose = FALSE;
- releaseconn(emdp);
- quitonclose = tquit;
- }
- else {
- if (makewind()) {
- /* out of memory */
- error("Not enough memory to make a window!");
- cu_exit(-1);
- }
- keyxinit();
- windowtitle(emdp, &emdp->appfile.fName);
- addwindmenu(emwindow);
-
- openconn(emdp); /* open up the connection */
- }
- closesettings(); /* close settings now resources obtained */
- emdp->resfid = 0;
-
- }
- }
- /* reset to last opened directory */
- if (SetVol((StringPtr) NULL, emdp->resvref))
- volerror();
- return(0);
- }
-
-
- /* save the current value of configuration variables in a configuration file;
- user selects filename through SFPutFile. Note that files are always
- closed except when being modified.
-
- this routine is always called in the emdp context... */
-
- saveconfig(twp, creator)
- struct winds * twp;
- long creator;
- {
- Point here;
- SFReply reply;
- Handle hconf;
- FInfo finfo;
- short curvol; /* current volume/wd */
- short newresvol; /* new vol from SF */
- long newresdir; /* new vol from SF */
- OSErr ferror;
- short newfile; /* flag to indicate new file made */
- WDPBRec WDPB;
-
-
- here.v = 60;
- here.h = 100;
- centerpoint(&here);
-
- newfile = FALSE;
-
- GetVol((StringPtr) NULL, &curvol);
- /* save & restore current volume for FILESAVE */
-
- /* fix globals so Put File appears in proper volume/directory */
- *SFSaveDisk = - twp->resvol;
- *CurDirStore = twp->resdir;
-
- emwdeactivate();
- SFPutFile(pass(here), "\PSave configuration in:",
- &twp->appfile.fName, (ProcPtr) NULL, &reply);
-
- if (reply.good) {
- short newresfid;
-
- if (EqualString(&reply.fName[0], &setfile[0])) {
- /* a problem: PMSP will *probably* find existing "CU3270 settings" file &
- open IT instead of file the user wants, so we ask him/her/it */
- if (! updatesetdlog()) {
- return(-1);
- }
- reply.vRefNum = *BootDrive;
- /* guarantee this happens by resetting to boot vol */
- }
- /* set volume */
- ferror = SetVol((StringPtr) NULL, reply.vRefNum);
- if ( (newresfid = myopenresfile(&reply.fName, reply.vRefNum, (Byte) fsRdWrPerm)) == NEG) {
- /* we need to make a new resource file */
-
- newfile = TRUE;
-
- CreateResFile(&reply.fName);
- if (ferror = ResError()) {
- error("Can't Create document");
- SetVol((StringPtr) NULL, curvol);
- return(-1);
- }
- if ( (newresfid = myopenresfile(&reply.fName, reply.vRefNum, (Byte) fsRdWrPerm)) == NEG) {
- /* attempt to open new file failed */
- error("Can't Open document");
- SetVol((StringPtr) NULL, curvol);
- return(-1);
- }
- /* copy existing key macros into new document
- copymacros();
- */
-
- /* copy resources: window & font size */
-
- reopenconfig(twp); /* open the old config file */
-
- copyresource('WIND', 0, twp->resfid, newresfid);
- copyresource('WIND', 1, twp->resfid, newresfid);
- copyresource('WIND', 2, twp->resfid, newresfid);
- copyresource('Fsiz', 0, twp->resfid, newresfid);
- copyresource('CONF', CONFID, twp->resfid, newresfid);
- copyresource('CONF', SERCONFID, twp->resfid, newresfid);
- copyresource('CONN', 0, twp->resfid, newresfid);
-
- UseResFile(newresfid);
-
- closeconfig(twp);
- /* close the old config file */
-
- /* fix the file type and creator so finder will do launches */
- GetFInfo(&reply.fName, reply.vRefNum, &finfo);
- finfo.fdType = 'TEXT';
- finfo.fdCreator = creator;
- SetFInfo(&reply.fName, reply.vRefNum, &finfo);
- }
- /* NOW we make the new file the default resource file for this window */
- twp->resfid = newresfid;
-
- SetVol((StringPtr) NULL, reply.vRefNum);
- twp->resvref = reply.vRefNum;
- twp->resvol = -(*SFSaveDisk);
- twp->resdir = *CurDirStore;
-
- twp->downvref = reply.vRefNum;
- twp->downvol = twp->resvol;
- twp->downdir = twp->resdir;
- /* save for the next SFget dialog */
-
- /* update the name for the next Save */
- ptoc(&reply.fName[0]);
- ptoc(&twp->appfile.fName);
- strcpy(&twp->appfile.fName, &reply.fName[0]);
- ctop(&reply.fName[0]);
- ctop(&twp->appfile.fName);
-
- /* save the resources */
- if ( (hconf = Get1Resource('CONF', CONFID)) == (Handle) NULL ) {
- /* we need to make a resource... */
- hconf = NewHandle((long) sizeof (struct config));
- if (hconf == (Handle) NULL) {
- error("Not enough memory to perform command");
- SetVol((StringPtr) NULL, curvol);
- closeconfig(twp);
- return(-1);
- }
- AddResource(hconf, 'CONF', (short) CONFID, "\P");
- if (ResError()) {
- error("Can't Create 'CONF' resource");
- SetVol((StringPtr) NULL, curvol);
- closeconfig(twp);
- return(-1);
- }
- }
- SetHandleSize(hconf, (Size) (sizeof (struct config)));
- /* make sure it's large enough */
- setconfig(hconf);
-
- if (saveresource(twp->resfid, twp->resvol, hconf)) {
- error("Can't Save document resource");
- SetVol((StringPtr) NULL, curvol);
- closeconfig(twp);
- return(-1);
- }
- ReleaseResource(hconf);
-
- savehostres(twp);
- /* save the hlasthost IP address resource */
-
- FlushVol((StringPtr) NULL, 0);
-
- SetVol((StringPtr) NULL, curvol);
-
- closeconfig(twp);
- /* close the new file */
-
- /* update the hostname */
- if (twp->hhostname) {
- DisposHandle(twp->hhostname);
- twp->hhostname = NULL;
- }
- PtrToHand(&twp->appfile.fName, &twp->hhostname,
- (long) (twp->appfile.fName.length + 1));
-
- if (twp->emwindow) {
- windowtitle(twp, &twp->appfile.fName);
- windmenutitle(twp);
- }
-
- twp->confchanged = FALSE;
- twp->newconf = FALSE;
-
- return(0);
- }
- /* previous vol/dir maintained */
- closeconfig(twp);
- return(-1);
- }
-
-
- /* copy a resource from one file to another;
- rsrc file order left as: current, dst, src */
-
- copyresource(restype, resnum, srcfid, dstfid)
- long restype;
- int resnum;
- short srcfid;
- short dstfid;
- {
- short saveresfid;
- Handle reshand;
- short junkid;
- long junktype;
- Str255 resname;
-
- saveresfid = CurResFile();
-
- /* get the resource & its name */
- UseResFile(srcfid);
- reshand = Get1Resource(restype, (short) resnum);
- if (reshand == NULL) {
- UseResFile(saveresfid);
- return(-1);
- }
- GetResInfo(reshand, &junkid, &junktype, &resname);
-
- /* detach, switch files, and save it */
- DetachResource(reshand);
- UseResFile(dstfid);
- AddResource(reshand, restype, (short) resnum, &resname);
- UpdateResFile(dstfid);
- ReleaseResource(reshand);
-
- UseResFile(saveresfid);
- }
-
-
- /* try to make a configuration file, return newresfid */
-
- makeconffile()
- {
- Handle hconf;
- FInfo finfo;
- short newresfid;
-
- copynotice(); /* remove for Stuart! but present the first time... */
-
- CreateResFile(&setfile[0]);
- if (ResError()) {
- return(-1);
- }
- newresfid = myopenresfile(&setfile[0], setresvref, (Byte) fsRdWrPerm);
- if (newresfid == -1) {
- newresfid = ResError();
- error(strsetcantopen);
- return(-1);
- }
-
- /* set FInfo so it can launch if desired */
- GetFInfo(&setfile[0], 0, &finfo);
- finfo.fdType = 'TEXT';
- finfo.fdCreator = creator;
- SetFInfo(&setfile[0], 0, &finfo);
-
- /* now copy defaults into conf file */
- getconfig(); /* set some defaults first */
- if ( (hconf = modresource(emdp, 'CONF', CONFID, sizeof(struct config)))
- == (Handle) NULL ) {
- return(-1);
- }
- setconfig(hconf);
-
- if (saveresource(newresfid, emdp->resvol, hconf)) {
- error("Can't save configuration resource");
- return(-1);
- }
- ReleaseResource(hconf);
-
- /* copy other user-modifiable resources */
- /* copyresource('CONF', GLOBCONFID, appresfid, newresfid); */
- copyresource('CUSS', 0, appresfid, newresfid);
- copyresource('CUSS', 1, appresfid, newresfid);
- copyresource('DEFG', 0, appresfid, newresfid);
- copyresource('DEFG', 1, appresfid, newresfid);
- copyresource('NETD', 0, appresfid, newresfid);
- copyresource('TMZO', 0, appresfid, newresfid);
-
- /* copyresource('LHST', 0, appresfid, newresfid); obsolete */
-
- copyresource('Fsiz', 0, appresfid, newresfid);
- copyresource('WIND', 0, appresfid, newresfid);
- copyresource('WIND', 1, appresfid, newresfid);
- copyresource('WIND', 2, appresfid, newresfid);
-
- FlushVol((StringPtr) NULL, 0);
-
- UseResFile(newresfid);
- return(newresfid);
- }
-
- /* query to user to determine whether he wishes to update the CU3270 settings
- file in the system folder, return FALSE if not */
-
- #define SETD_OK 1
- #define SETD_CANCEL 2
-
- updatesetdlog()
- {
- DialogPtr setdial;
- short item_id;
- short type;
- Rect rect;
- Handle hitem;
- /* general purpose GetDItem vars */
- GrafPtr oport;
-
- GetPort(&oport);
-
- emwdeactivate();
- if ((setdial = GetNewDialog(DSETTINGS, (Ptr) NULL, (WindowPtr) (-1))) == NULL)
- return(-1);
-
- centerwind(setdial);
-
- SetCursor(&arrow);
- SetPort(setdial);
- modaldialog = TRUE;
-
- GetDItem(setdial, SETD_OK, &type, &hitem, &rect);
- buthilite(&rect);
- /* hilite "OK" key */
-
- while (TRUE) {
- ModalDialog((ProcPtr) alfilter, &item_id);
- switch (item_id) {
- case SETD_CANCEL: {
- SetPort(oport);
- DisposDialog(setdial);
- modaldialog = FALSE;
- return(0);
- }
- case SETD_OK: {
- SetPort(oport);
- DisposDialog(setdial);
- modaldialog = FALSE;
- return(TRUE);
- }
- default: {
- break;
- }
- }
- }
- }
-
-
-
- /* return a Handle to a fresh resource; kill the old one if necessary */
-
- Handle
- modresource(twp, restype, resnum, size)
- struct winds * twp;
- long restype;
- int resnum;
- unsigned int size;
- {
- Handle hconf;
-
- if ( (hconf = Get1Resource(restype, (short) resnum)) != NULL) {
- /* a resource is already in the current resource file, so kill it */
- RmveResource(hconf);
- if (ResError()) {
- error("Can't Delete resource");
- }
- UpdateResFile(twp->resfid);
- DisposHandle(hconf);
- }
- /* add new resource */
- hconf = NewHandle((long) size);
- if (hconf == (Handle) NULL)
- return((Handle) NULL);
- AddResource(hconf, restype, (short) resnum, "\P");
- if (ResError()) {
- return((Handle) NULL);
- }
- return(hconf);
- }
-
-
- /* save the resource with handle hconf in the current resource file */
- /* TODO does FlushVol() require real vol as we are using? */
-
- saveresource(resfid, resvol, hconf)
- short resfid;
- short resvol;
- Handle hconf;
- {
- ChangedResource(hconf);
- if (ResError()) {
- return(-1);
- }
- UpdateResFile(resfid);
- if (ResError()) {
- return(-1);
- }
- FlushVol((StringPtr) NULL, (short) resvol); /* flush the volume */
- return(0);
- }
-
-
- /* set some unavoidable historical defaults */
-
- defaultconf()
- {
- emdp->escmap = TRUE;
- emdp->ucb.u_tftp = TFNO;
- emdp->ucb.u_ask = TRUE;
-
- emdp->normfont = 201; /* normal font ID */
- emdp->highfont = 202; /* bold font ID */
- emdp->vtfont = 74; /* vt100 graphics font ID */
-
- emdp->changecurs = TRUE; /* make cursor blink */
- wrap_around = emdp->wrap_around = TRUE; /* wrap at end of line if true */
-
- emdp->keypad = KEYPAD3; /* ibm emdp->keypad mode */
- emdp->typeahead = TRUE; /* ibm do typeahead */
- emdp->nullsareblanks = TRUE; /* causes imbedded nulls to be sent as blanks */
- emdp->squeezeblanks = TRUE; /* squeeze blanks and not just nulls on insert */
-
- emdp->ibmcolormap = asccolormap;
-
- emdp->vtkeypad = FALSE; /* let host set keypad */
-
- emdp->logsession = FALSE; /* dont' log session */
- emdp->filesession = FALSE; /* dont' log session */
-
- emdp->editload = TRUE; /* automatically load file ~.edit into .edit */
- emdp->editupwrap = FALSE; /* DONT automatically wrap text */
- emdp->editdownwrap = FALSE; /* DONT automatically wrap text */
-
- emdp->autohangup = FALSE; /* automatically hangup serial port on close */
-
- emdp->vtjumpscroll = FALSE;
- emdp->keypadswitch = FALSE;
- emdp->logerase = FALSE;
- emdp->editupwrap = FALSE;
- emdp->linecount = 24;
- emdp->linelength = 80;
- emdp->ibm_type = IBMMOD2; /* 3278-2 (model 2) by default */
-
- setcontext(emdp); /* update globals */
- localconfig();
- /* this routine must be present in the application to handle less
- general parameters such as serial port stuff */
- }
-
-
- /* open a document file */
-
- reopenconfig(thedp)
- struct winds * thedp;
- {
- WDPBRec WDPB;
- char errtext[200];
- extern short setresfid;
-
- if (thedp->resfid) {
- return(0);
- }
-
- WDPB.ioCompletion = NULL;
- WDPB.ioNamePtr = NULL;
-
- if (thedp->newconf) {
- if (opensettings()) {
- /* no config, default to the application */
-
- thedp->resfid = appresfid;
- thedp->resvref = appvref;
- thedp->resvol = appvol;
- thedp->resdir = appdir;
-
- return(-1);
- }
- else {
- /* we have opened the settings file, identify this file with it */
-
- thedp->resfid = setresfid;
- thedp->resvref = setresvref;
- /* TODO is this the folder we want it in ? */
- }
- }
- else {
- if (SetVol((StringPtr) NULL, thedp->resvref))
- volerror();
- if ((thedp->resfid = myopenresfile(&thedp->appfile.fName, thedp->resvref, (Byte) fsRdWrPerm)) == -1) {
- /* no config, default to the application */
- thedp->resfid = appresfid;
- thedp->resvref = appvref;
- thedp->resvol = appvol;
- thedp->resdir = appdir;
-
- return(-1);
- }
- }
- return(0);
- }
-
-
-
- closeconfig(twp)
- struct winds * twp;
- {
- if (twp->resfid == 0)
- /* it's not open */
- return(0);
-
- if (twp->resfid == appresfid) {
- /* we're using the CU3270 settings resource file, leave it open */
- twp->resfid = 0;
- return(0);
- }
-
- if (twp->resfid == setresfid)
- /* if it happens to be the settings file, make sure global is reset */
- setresfid = 0;
-
- CloseResFile(twp->resfid);
- twp->resfid = 0;
- }
-
-
- /* reset the directory to the home directory for this window's document */
-
- mac_setconfvol()
- {
- if (SetVol((StringPtr) NULL, emdp->resvref))
- volerror();
-
- }
-
-
- /* reset the directory to this session's download directory */
-
- mac_setdownvol()
- {
- if (SetVol((StringPtr) NULL, emdp->downvref))
- volerror();
-
- }
-
-
- getglobalconf()
- {
- Handle hglobal;
- struct globalconfig * confp;
- int version;
-
- /* TODO save name ? */
- if ((hglobal = GetResource('CONF', GLOBCONFID)) != NULL) {
- HLock(hglobal);
- confp = (struct globalconfig *) *hglobal;
-
- tftpserve = confp->tftpserve;
- tftpask = confp->tftpask;
- trydsdraw = confp->trydsdraw;
- riskydsdraw = confp->riskydsdraw;
- quitonclose = confp->quitonclose;
-
- if (GetHandleSize(hglobal) > 10) {
- /* kluge because version # foolishly not included in original struct */
- version = confp->version;
- }
- else {
- version = 0;
- }
- if (version >= 1) {
- mtcpsendasync = confp->mtcpsendasync;
- }
- else {
- mtcpsendasync = FALSE;
- }
- if (version >= 2) {
- edresetselect = confp->edresetselect;
- }
- else {
- edresetselect = TRUE;
- }
- if (version >= 3) {
- keypadswitch = confp->keypadswitch;
- }
- else {
- keypadswitch = FALSE;
- }
- if (version >= 4) {
- courierprint = confp->courierprint;
- }
- else {
- courierprint = FALSE;
- }
- HUnlock(hglobal);
- ReleaseResource(hglobal);
- }
- else {
- /* stock configuration */
- tftpserve = TFNO;
- tftpask = TFYES;
- trydsdraw = FALSE;
- riskydsdraw = FALSE;
- quitonclose = FALSE;
- mtcpsendasync = FALSE;
- edresetselect = TRUE;
- keypadswitch = FALSE;
- courierprint = FALSE;
- }
- }
-
-
- /* open the "Comet Settings" file */
-
- opensettings()
- {
- if (setresfid)
- return(0);
-
- if (SetVol((StringPtr) NULL, setresvref))
- error("Can't set volume to Default");
-
- if ((setresfid = myopenresfile(&setfile[0], setresvref, (Byte) fsRdWrPerm)) == -1) {
- /* can't reopen Settings file, give up */
- error(strsetcantopen);
- setresfid = 0;
- return(-1);
- }
- return(0);
- }
-
-
- /* close the "Comet Settings" file */
-
- closesettings()
- {
- if (setresfid)
- CloseResFile(setresfid);
- setresfid = 0;
- }
-
-
- /* save important global vars in CONF resource in settings file */
-
- saveglobalconfig()
- {
- Handle hglobal;
- struct globalconfig * confp;
-
- if (opensettings())
- return(-1);
-
- if ((hglobal = GetResource('CONF', GLOBCONFID)) == NULL) {
- /* we need to make a resource... */
- hglobal = NewHandle((long) sizeof (struct globalconfig));
- if (hglobal == (Handle) NULL) {
- return(-1);
- }
- AddResource(hglobal, 'CONF', (short) GLOBCONFID, "\P");
- if (ResError()) {
- return(-1);
- }
- }
- SetHandleSize(hglobal, (Size) (sizeof (struct globalconfig)));
- /* make sure it's large enough */
-
- HLock(hglobal);
- confp = (struct globalconfig *) *hglobal;
-
- confp->tftpserve = tftpserve;
- confp->tftpask = tftpask;
- confp->trydsdraw = trydsdraw;
- confp->riskydsdraw = riskydsdraw;
- confp->quitonclose = quitonclose;
- confp->version = GLOBVERSION;
- confp->mtcpsendasync = mtcpsendasync;
- confp->edresetselect = edresetselect;
- confp->keypadswitch = keypadswitch;
- confp->courierprint = courierprint;
-
- HUnlock(hglobal);
- saveresource(setresfid, setresvol, hglobal);
- ReleaseResource(hglobal);
-
- closesettings();
- return(0);
- }
-
-
- volerror()
- {
- error(strbadvol);
- SetVol((StringPtr) NULL, appvol);
- }
-
-
-
- myopenresfile(fName, resvref)
- Str255 * fName;
- short resvref;
- {
- short resfid;
- short reserror;
- char errtext[200];
-
- SetVol((StringPtr) NULL, resvref);
-
- if (environs.systemVersion)
- resfid = OpenRFPerm(fName, resvref, (Byte) fsRdWrPerm);
- else
- resfid = OpenResFile(fName);
-
- return(resfid);
- }
-
- /* set the default directories for a new window */
-
- setwindvols(twp)
- struct winds * twp;
- {
- twp->resvref = setresvref; /* settings directory--the system folder */
- twp->resvol = appvol; /* new settings default into app directory */
- twp->resdir = appdir;
-
- twp->downvref = appvref; /* download defaults into app directory */
- twp->downvol = appvol;
- twp->downdir = appdir;
- }
-
-
- /* set the resource vref, vol, & dir to the current directory */
-
- setemdpresvol()
- {
- WDPBRec WDPB;
-
- WDPB.ioCompletion = NULL;
- WDPB.ioNamePtr = NULL;
-
- PBHGetVol(&WDPB, (Boolean) FALSE);
- emdp->resvref = WDPB.ioVRefNum;
- emdp->resvol = WDPB.ioWDVRefNum;
- emdp->resdir = WDPB.ioWDDirID;
-
- emdp->downvref = WDPB.ioVRefNum;
- emdp->downvol = WDPB.ioWDVRefNum;
- emdp->downdir = WDPB.ioWDDirID;
- }
-
-